package com.d3works.apps.production.service.productionorder;

import com.d3works.apps.base.db.Product;
import com.d3works.apps.production.db.BillOfMaterial;
import com.d3works.apps.production.db.ProductionOrder;
import com.d3works.apps.production.service.manuforder.ManufOrderService.ManufOrderOriginType;
import com.d3works.apps.sale.db.SaleOrder;
import com.d3works.apps.sale.db.SaleOrderLine;
import com.d3works.exception.D3worksException;
import com.google.inject.persist.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Set;

public interface ProductionOrderService {

  public ProductionOrder createProductionOrder(SaleOrder saleOrder) throws D3worksException;

  public String getProductionOrderSeq() throws D3worksException;

  /**
   * Generate a Production Order
   *
   * @param product Product must be passed in param because product can be different of bill of
   *     material product (Product variant)
   * @param billOfMaterial
   * @param qtyRequested
   * @param businessProject
   * @param startDate
   * @return
   * @throws D3worksException
   */
  @Transactional(rollbackOn = {Exception.class})
  public ProductionOrder generateProductionOrder(
      Product product,
      BillOfMaterial billOfMaterial,
      BigDecimal qtyRequested,
      LocalDateTime startDate)
      throws D3worksException;

  /**
   * @param productionOrder
   * @param product
   * @param billOfMaterial
   * @param qtyRequested
   * @param startDate
   * @param endDate
   * @param saleOrder
   * @param saleOrderLine
   * @param manufOrderOriginType
   * @return
   * @throws D3worksException
   */
  @Transactional(rollbackOn = {Exception.class})
  public ProductionOrder addManufOrder(
      ProductionOrder productionOrder,
      Product product,
      BillOfMaterial billOfMaterial,
      BigDecimal qtyRequested,
      LocalDateTime startDate,
      LocalDateTime endDate,
      SaleOrder saleOrder,
      SaleOrderLine saleOrderLine,
      ManufOrderOriginType manufOrderOriginType)
      throws D3worksException;

  @Transactional(rollbackOn = {Exception.class})
  public Set<ProductionOrder> updateStatus(Set<ProductionOrder> productionOrderSet);
}
